package com.chaoyi.service.Impl;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Part;

import org.springframework.stereotype.Service;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.dao.mysql.FictionMapper;
import com.chaoyi.model.Fiction;
import com.chaoyi.service.FictionService;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.oss.ApkOSSConfigure;
import com.chaoyi.util.oss.ApkOSSManageUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;

@Service
public class FictionServiceImpl implements FictionService{
	@Resource
	FictionMapper fictionMapper;

	public List<Fiction> findList(String offset, String limit) {
		return fictionMapper.findList(offset,limit);
	}

	public int findCount() {
		return fictionMapper.findCount();
	}

	@Override
	public int saveFiction(Fiction fiction) {
		return fictionMapper.saveFiction(fiction);
	}

	@Override
	public Fiction findFictionOne(int id) {
		return fictionMapper.findFictionOne(id);
	}

	@Override
	public int alertFictionSave(Fiction fiction) {
		return fictionMapper.alertFictionSave(fiction);
	}

	@Override
	public int deleteFiction(int id) {
		return fictionMapper.deleteFiction(id);
	}
	
	@Override
	public String uploadOSS(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
//		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.fictionPath,
//				fileName);
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.fictionPath, fileName);
	}

}
